#ifndef SSD1306_H_
#define SSD1306_H_

#include "stm32f4xx.h"

extern const uint8_t LCD_Buffer[][22];
extern const uint8_t OLED_Logo[];
extern const uint8_t OLED_USB_mode[];

extern __IO uint8_t LCD_X,LCD_Y;

#define COMAND				0x00
#define DATA				0x40

#define SSD1306_RESET_PORT	GPIOC
#define SSD1306_RESET_PIN	GPIO_PIN_3

#define SSD1306_CS_PORT		GPIOC
#define SSD1306_CS_PIN		GPIO_PIN_2

#define SSD1306_SCLK_PORT	GPIOF
#define SSD1306_SCLK_PIN	GPIO_PIN_6

#define SSD1306_SDIN_PORT	GPIOF
#define SSD1306_SDIN_PIN	GPIO_PIN_7

#define SSD1306_RCC_AHB		AHB1ENR
#define SSD1306_RCC_EN		( RCC_AHB1ENR_GPIOFEN | RCC_AHB1ENR_GPIOCEN )

#define SSD1306_LCDWIDTH					128
#define SSD1306_LCDHEIGHT					64
#define SSD1306_DEFAULT_SPACE				5
// Commands
#define SSD1306_SETCONTRAST 				0x81
#define SSD1306_DISPLAYALLON_RESUME 		0xA4
#define SSD1306_DISPLAYALLON 				0xA5
#define SSD1306_NORMALDISPLAY 				0xA6
#define SSD1306_INVERTDISPLAY 				0xA7
#define SSD1306_DISPLAYOFF 					0xAE
#define SSD1306_DISPLAYON 					0xAF

#define SSD1306_SETDISPLAYOFFSET 			0xD3
#define SSD1306_SETCOMPINS 					0xDA

#define SSD1306_SETVCOMDETECT 				0xDB

#define SSD1306_SETDISPLAYCLOCKDIV 			0xD5
#define SSD1306_SETPRECHARGE 				0xD9

#define SSD1306_SETMULTIPLEX 				0xA8

#define SSD1306_SETLOWCOLUMN 				0x00
#define SSD1306_SETHIGHCOLUMN 				0x10

#define SSD1306_SETSTARTLINE 				0x40

#define SSD1306_MEMORYMODE 					0x20
#define SSD1306_COLUMNADDR 					0x21
#define SSD1306_PAGEADDR   					0x22

#define SSD1306_COMSCANINC 					0xC0
#define SSD1306_COMSCANDEC 					0xC8

#define SSD1306_SEGREMAP 					0xA0

#define SSD1306_CHARGEPUMP 					0x8D

#define SSD1306_EXTERNALVCC 				0x1
#define SSD1306_SWITCHCAPVCC 				0x2

// Scrolling #defines
#define SSD1306_ACTIVATE_SCROLL 			0x2F
#define SSD1306_DEACTIVATE_SCROLL 			0x2E
#define SSD1306_SET_VERTICAL_SCROLL_AREA 	0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 	0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 		0x27
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL	0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL		0x2A

void SSD1306_GPIO_Init(void);
void SSD1306_Init(void);
void LCD_Commmand(uint8_t ControByte, uint8_t DataByte);

void LCD_Print(char c);
void LCD_Printf(char* buf);
void LCD_Goto(uint8_t x, uint8_t y);
void LCD_ClearFull(void);
void LCD_DrawImageFullScreen(uint8_t * buf);
void LCD_Clear(uint8_t x, uint8_t y, uint8_t count);
void LCD_draw8x8(uint8_t * buffer, uint8_t x, uint8_t y);
void LCD_DrawImageFullScreen(uint8_t * buf);
void LCD_DrawImageRegion(uint8_t * buf, uint8_t sizeX, uint8_t sizeY);

#endif
